import axios from 'axios'

const read = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 50000,
})

read.interceptors.request.use(
    config => {
        if(localStorage.token){//判断是否有token
            config.headers.Authorization = 'Bearer ' + localStorage.token;
        }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

read.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    }
)

const write = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 10000,
})

write.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

write.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    }
)
 ////////////////////////
const Wread = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 100000,
})

Wread.interceptors.request.use(
    config => {
        if(localStorage.getItem('token')){
            config.headers['Authorization'] = 'Bearer ' + localStorage.getItem('token')
        }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

Wread.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    }
)

const Wwrite = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 100000,
})

Wwrite.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

Wwrite.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    }
)
////////////////////
//#region 生产计划axios

const Productionwrite = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 5000,
})

Productionwrite.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

Productionwrite.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    })

    const ProductionRead = axios.create({
        baseURL: 'http://8.154.44.176:8000',
        timeout: 5000,
    })

//#endregion
//#region 物料模块拦截器
const Materialread = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 10000,
})

Materialread.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

Materialread.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    }
)

const Materialwrite = axios.create({
    baseURL: 'http://8.154.44.176:8000',
    timeout: 10000,
})

Materialwrite.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

Materialwrite.interceptors.response.use(
    res => {
        return res;
    },
    error => {
        return Promise.reject(error)
    })


//#endregion

export { read, write,ProductionRead,Productionwrite,Materialwrite,Materialread,Wwrite,Wread }
